//
//  MeViewController.m
//  item-NetEaseNews-tyw
//
//  Created by tyw on 15/9/29.
//  Copyright (c) 2015年 tyw. All rights reserved.
//

#import "MeViewController.h"

@interface MeViewController ()

@end

@implementation MeViewController {
    UITableView* _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self _createTableView];
}

- (void)viewWillAppear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = NO;
}

- (void)_createTableView {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight-tabBarHeight)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    [self setTableHeaderView];
}

- (void)setTableHeaderView {
    UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 280)];
    
    //第一部分，红色的
    UIView* redView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, kWidth, 220)];
    redView.backgroundColor = kNetEaseRedColor;
    redView.userInteractionEnabled = YES;
    [headerView addSubview:redView];
    //设置按钮
    UIButton* setBtn = [[UIButton alloc] initWithFrame:CGRectMake(kWidth-50, 30, 40, 20)];
    [setBtn setTitle:@"设置" forState:UIControlStateNormal];
    setBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [setBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [redView addSubview:setBtn];
    //头像
    UIImageView* iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth/2-25, 80, 50, 50)];
    iconImgView.layer.cornerRadius = 25;
    iconImgView.layer.masksToBounds = YES;
    iconImgView.image = [UIImage imageNamed:@"1.jpg"];
    [redView addSubview:iconImgView];
    //立即登录
    UILabel* logInLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, iconImgView.bottom+10, kWidth, 20)];
    logInLabel.text = @"立即登录";
    logInLabel.textColor = [UIColor whiteColor];
    logInLabel.textAlignment = NSTextAlignmentCenter;
    logInLabel.font = [UIFont systemFontOfSize:14];
    [redView addSubview:logInLabel];
    
    //第二部分
    NSArray* imgNameArray = @[@"user_read_icon",@"user_favor_icon",@"user_comment_icon",@"user_coin_icon"];
    NSArray* labelTextArray = @[@"阅读",@"收藏",@"跟帖",@"金币"];
    for (int i = 0; i < 4; i++) {
        //图标
        UIImageView* imgView = [[UIImageView alloc] initWithFrame:CGRectMake(i*kWidth/4+(kWidth/4/2-20), 210, 40, 40)];
        imgView.image = [UIImage imageNamed:imgNameArray[i]];
        imgView.contentMode = UIViewContentModeScaleAspectFit;
        [headerView addSubview:imgView];
        //标题
        UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(i*kWidth/4, imgView.bottom+5, kWidth/4, 20)];
        label.text = labelTextArray[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor grayColor];
        label.font = [UIFont systemFontOfSize:12];
        [headerView addSubview:label];
        //细线
        if (i) {
            UIImageView* line = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth/4*i, 200, 0.3, 80)];
            UIImage* lingImg = [UIImage imageNamed:@"home_channel_bar_line"];
            [lingImg stretchableImageWithLeftCapWidth:1 topCapHeight:1];
            line.image = lingImg;
            [headerView addSubview:line];
        }
    }
    
    _tableView.tableHeaderView = headerView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else if (section == 1) {
        return 3;
    } else {
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    UIImageView* imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
    [cell.contentView addSubview:imgView];
    
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(40, 10, 100, 20)];
    label.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label];
    
    
    if (indexPath.section == 0) {
        imgView.image = [UIImage imageNamed:@"user_set_icon_message"];
        label.text = @"我的消息";
    } else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            imgView.image = [UIImage imageNamed:@"user_set_icon_mall"];
            label.text = @"金币商城";
        } else if (indexPath.row == 1) {
            imgView.image = [UIImage imageNamed:@"user_set_icon_mission"];
            label.text = @"金币任务";
        } else {
            imgView.image = [UIImage imageNamed:@"user_set_icon_wallet"];
            label.text = @"我的钱包";
        }
    } else {
        imgView.image = [UIImage imageNamed:@"user_set_icon_mail"];
        label.text = @"我的邮箱";
    }
    
    //细线
//    UIImageView* line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 39.7, 0.3, kWidth)];
//    UIImage* lingImg = [UIImage imageNamed:@"home_channel_bar_line"];
//    [lingImg stretchableImageWithLeftCapWidth:1 topCapHeight:1];
//    line.image = lingImg;
//    [cell.contentView addSubview:line];

    cell.backgroundColor = [UIColor clearColor];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 5;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 5)];
    view.backgroundColor = [UIColor grayColor];
    view.alpha = 0.3;
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end
